#ifndef QQ_CHAT_VIEW
#define QQ_CHAT_VIEW

#include <qfiledialog.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qstackedlayout.h>
#include <qstandarditemmodel.h>
#include <qtextdocument.h>
#include <qtextobject.h>

#include <ElaListView.h>
#include <ElaMessageBar.h>
#include <ElaPushButton.h>
#include <ElaScrollPage.h>
#include <ElaToolBar.h>

#include "api/QQSystemApi.h"

#include "core/QQConfig.h"
#include "core/QQSettings.h"

#include "widget/QQMaskWidget.h"
#include "widget/QQTextEdit.h"
#include "widget/QQContentDialog.h"

#include "chat/QQAudioView.h"
#include "chat/QQEmojiView.h"
#include "chat/QQFileView.h"
#include "chat/QQVideoView.h"
#include "chat/QQChatIndexDelegate.h"
#include "chat/QQChatMessageDelegate.h"
#include "chat/QQChatMessageModel.h"

class QQChatView : public ElaScrollPage
{
	Q_OBJECT
public:
	QQChatView(QWidget* parent = nullptr);
	~QQChatView();

	void showMessageBar(const QString& message);

	void loadIndex(const QQChatIndexItem& index);
	void loadIndexs(const QList<QQChatIndexItem>& indexs);

	void loadMessageOnView(const QQMessageItem& message);
	void loadMessagesOnView(const QList<QQMessageItem>& messages);

	void loadEmojiDataOnView(const QList<QQChatEmoji>& emojis);

	void loadPictureInInput(const QStringList& filenames);
	int openPictureToFileDialog();
	int openFileSendDialog(const QFileInfoList& fileinfos);

	void openAudioView(int detail, const QString& account, const QString& nickname, QPixmap pixmap);
	void startRealCommunicateAudio();
	void stopRealCommunicateAudio(QQAudioView::StopType type);

	void openVideoView(int detail, const QString& account, const QString& nickname, QPixmap pixmap);
	QPair<QWidget*, QWidget*> startRealCommunicateVideo();
	void stopRealCommunicateVideo(QQVideoView::StopType type);
	void setVideoBackground(const QPixmap& pixmap);

	void doMousePress(QPoint pos, Qt::MouseButton type);
signals:
	void loadMessages(const QString& account);
	void loadEmojiData(const QString& account);

	void checkPicture(const QString& account, const QStringList& filenames);
	void checkFile(const QString& account, const QStringList& filenames);
	void sendMessage(const QString& account, const QString& message);

	void changeAudioMicrophoneState(bool opened);
	void sendRealCommunicateAudio(const QString& account);
	void acceptRealCommunicateAudioByMe(const QString& account);
	void refuseRealCommunicateAudioByMe(const QString& account);

	void changeVideoMicrophoneState(bool opened);
	void changeVideoCameraState(bool opened);
	void sendRealCommunicateVideo(const QString& account);
	void acceptRealCommunicateVideoByMe(const QString& account);
	void refuseRealCommunicateVideoByMe(const QString& account);
public slots:
	void doUpdateFileProgress(const QString& filename, int progress);
protected:
	void dragEnterEvent(QDragEnterEvent* event)override;
	void dragMoveEvent(QDragMoveEvent* event)override;
	void dropEvent(QDropEvent* event)override;
private slots:
	void doIndexClicked(const QModelIndex& index);
	void doToolBarClicked(QAction* action);
	void doRealCommunicateToolBarClicked(QAction* action);

	void doLoadEmojiToInput(const QString& emoji, int type);
	void doSendMessageClicked();
private:
	bool mIsDragAllPicture = true;
	QQContentDialog* mPictureToFileDialog;

	ElaListView* mIndexs;
	QStandardItemModel* mIndexsModel;
	QQChatIndexDelegate* mIndexsDelegate;

	ElaListView* mMessages;
	QQChatMessageModel* mMessagesModel;
	QQChatMessageDelegate* mMessagesDelegate;
	QQMaskWidget* mDragMessageMask;

	ElaToolBar* mToolBar;
	QQEmojiView* mEmojiView;
	QQFileView* mFileView;

	ElaToolBar* mRealCommunicateToolBar;
	QQAudioView* mAudioView;
	QQVideoView* mVideoView;

	QQTextEdit* mMessageInput;
	ElaPushButton* mMessageSend;
	ElaPushButton* mMessageClear;
	QQMaskWidget* mDragMessageInputMask;
};

#endif // !QQ_CHAT_VIEW

